import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-04-01
 * Time: 12:11
 */
public class Demo2 {

    public static void main1(String[] args) throws InterruptedException {
        List<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                synchronized (arrayList) {
                    arrayList.add(1);
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                synchronized (arrayList) {
                    arrayList.add(1);
                }
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(arrayList.size());


    }
}
